1 Data

Petra’s code with file locations changed to load in datasets and reading original .txt files instead of converted .RDS files.

1.1 Upload raw data and select variables

# Read in raw data and save as RDS
#dd0 <- read_delim("I:/SHARE/USERS/plebeau/CGM/T1D study data/DataTables/HDeviceCGM.txt", delim = "|") 
#export(dd0, "I:/SHARE/USERS/plebeau/CGM/T1D study data/DataTables/HDeviceCGM.rds")
dd0 <- read_delim("../data/HDeviceCGM.txt", delim = "|") %>% 
  janitor::clean_names() %>% 
  mutate_if(is.character,as.factor) %>%
  mutate(pt_id=as.factor(pt_id)) %>%
  filter(!record_type %in% c("Calibration"))
Parsed with column specification:
cols(
  RecID = col_double(),
  ParentHDeviceUploadsID = col_double(),
  PtID = col_double(),
  SiteID = col_double(),
  DeviceDtTmDaysFromEnroll = col_double(),
  DeviceTm = col_time(format = ""),
  DexInternalDtTmDaysFromEnroll = col_double(),
  DexInternalTm = col_time(format = ""),
  RecordType = col_character(),
  GlucoseValue = col_double()
)
# Metadata
#dd1 <- read_delim("I:/SHARE/USERS/plebeau/CGM/T1D study data/DataTables/HScreening.txt", delim = "|") 
#export(dd1, "I:/SHARE/USERS/plebeau/CGM/T1D study data/DataTables/HScreening.rds")
dd1 <- read_delim("../data/HScreening.txt", delim = "|") %>% 
  janitor::clean_names() %>%  
  mutate_if(is.character,as.factor) %>%
  mutate(pt_id=as.factor(pt_id)) %>%
  select(c(pt_id, site_id, gender, ethnicity, diag_age, oth_gluc_lower_med, edu_level, 
           weight, height, cgm_use_status))
Parsed with column specification:
cols(
  .default = col_double(),
  Gender = col_character(),
  Ethnicity = col_character(),
  Race = col_character(),
  SHMostRec = col_character(),
  DKAMostRec = col_character(),
  OthGlucLowerMed = col_character(),
  EduLevel = col_character(),
  AnnualInc = col_character(),
  InsSCHIP = col_logical(),
  InsIndian = col_logical(),
  InsOtherGov = col_logical(),
  InsUnknown = col_logical(),
  PEAbnormal = col_character(),
  CGMUseStatus = col_character(),
  CGMUseDuration = col_character(),
  CGMUseDevice = col_character(),
  CGMDLoadMinDays = col_character(),
  CGMGlucUnder60 = col_character()
)
See spec(...) for full column specifications.
#dd2 <- read_delim("I:/SHARE/USERS/plebeau/CGM/T1D study data/DataTables/HPtRoster.txt", delim = "|") 
#export(dd2, "I:/SHARE/USERS/plebeau/CGM/T1D study data/DataTables/HPtRoster.rds")

dd2 <- read_delim("../data/HPtRoster.txt", delim = "|") %>% 
  janitor::clean_names() %>% 
  mutate_if(is.character,as.factor) %>% 
  mutate(pt_id=as.factor(pt_id)) %>%
  select(pt_id, pt_status, trt_group, age_as_of_enroll_dt)
Parsed with column specification:
cols(
  RecID = col_double(),
  PtID = col_double(),
  SiteOrig = col_double(),
  SiteID = col_double(),
  RandDtDaysAfterEnroll = col_double(),
  PtStatus = col_character(),
  TrtGroup = col_character(),
  AgeAsOfEnrollDt = col_double()
)
ds_subject <- inner_join(dd1,dd2)
Joining, by = "pt_id"
# export(ds_subject, file="I:/SHARE/USERS/plebeau/CGM/T1D study data/AnalysisData/ds_subject.RDS")

# Visit data
#dd3 <- read_delim("I:/SHARE/USERS/plebeau/CGM/T1D study data/DataTables/HVisitInfo.txt", delim = "|") 
#export(dd3, "I:/SHARE/USERS/plebeau/CGM/T1D study data/DataTables/HVisitInfo.rds")
ds_visit <- read_delim("../data/HVisitInfo.txt", delim = "|") %>% 
  janitor::clean_names() %>%  
  mutate_if(is.character,as.factor) %>%
  mutate(pt_id=as.factor(pt_id)) %>%
  filter(visit %in% c('Randomization','Week 3 Visit', 'Week 6 Visit', 'Week 13 Visit',
                      'Week 19 Visit', 'Week 26 Visit')) %>% 
  droplevels() %>% 
  mutate(visit = fct_relevel(visit, c("Randomization", "Week 3 Visit", 
                                        "Week 6 Visit", "Week 13 Visit", "Week 19 Visit", "Week 26 Visit"))) %>% 
  mutate(visit_dt_days_from_enroll_lag7 = visit_dt_days_from_enroll - 7) %>% 
  mutate(visitnum = fct_recode(visit, "0" = "Randomization",
                            "1" = "Week 3 Visit",
                            "2" = "Week 6 Visit",
                            "3" = "Week 13 Visit",
                            "4" = "Week 19 Visit",
                            "5" = "Week 26 Visit")) %>% 
  select(pt_id, visit, visitnum, visit_dt_days_from_enroll, visit_dt_days_from_enroll_lag7)
Parsed with column specification:
cols(
  ParentLoginVisitID = col_double(),
  RecID = col_double(),
  PtID = col_double(),
  SiteID = col_double(),
  Visit = col_character(),
  VisitDtDaysFromEnroll = col_double(),
  OutOfWin = col_double(),
  OutOfWinReason = col_character(),
  VisitMiss = col_double(),
  VisitMissReason = col_character()
)
# export(ds_visit, file="I:/SHARE/USERS/plebeau/CGM/T1D study data/AnalysisData/ds_visit.RDS")

1.2 Assign visits to cgm data

table(ds_visit$visit)

Randomization  Week 3 Visit  Week 6 Visit Week 13 Visit Week 19 Visit Week 26 Visit 
          226           224           224           221           219           217 
# Get CGM data from 7 days prior to the visit
ds_cgm <- left_join(dd0, ds_visit, by = c("pt_id")) %>% 
  filter( (device_dt_tm_days_from_enroll >= visit_dt_days_from_enroll_lag7 &
             device_dt_tm_days_from_enroll <= visit_dt_days_from_enroll) ) %>% 
  select(pt_id, visit, visitnum, visit_dt_days_from_enroll_lag7, visit_dt_days_from_enroll,
         device_dt_tm_days_from_enroll, device_tm, glucose_value)

#export(ds_cgm, file = "I:/SHARE/USERS/plebeau/CGM/T1D study data/AnalysisData/ds_cgm.RDS")

1.3 Codebook metadata

ds_subject

13 Variables   226 Observations

pt_id
nmissingdistinct
2260226
lowest : 2 3 5 7 8 , highest: 289 290 291 292 293
site_id
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
2260140.9948.2215.112 1.0 2.0 5.0 8.012.014.515.0
 Value          1     2     3     5     6     7     8     9    10    11    12    13
 Frequency     15    16    17    19    27    14     8    14    15    18    13    12
 Proportion 0.066 0.071 0.075 0.084 0.119 0.062 0.035 0.062 0.066 0.080 0.058 0.053
                       
 Value         14    15
 Frequency     15    23
 Proportion 0.066 0.102
 

gender
nmissingdistinct
22602
 Value          F     M
 Frequency    112   114
 Proportion 0.496 0.504
 

ethnicity
image
nmissingdistinct
22603
 Value          Hispanic or Latino Not Hispanic or Latino   Unknown/not reported
 Frequency                       9                    216                      1
 Proportion                  0.040                  0.956                  0.004
 

diag_age
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
2260550.99920.7514.9 5.00 6.0010.0018.0028.7539.0047.00
lowest : 0 1 2 3 4 , highest: 57 58 59 60 61
oth_gluc_lower_med
nmissingdistinct
22602
 Value         No   Yes
 Frequency    210    16
 Proportion 0.929 0.071
 

edu_level
image
nmissingdistinct
22157
Associate Degree (9, 0.041), Bachelor's Degree (110, 0.498), Doctorate Degree (6, 0.027), High school graduate/diploma/GED (8, 0.036), Master's Degree (47, 0.213), Professional Degree (11, 0.050), Some college but no degree (30, 0.136)
weight
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
2260177181.2217.68 59.00 62.15 69.73 79.50 91.40102.35110.68
lowest : 50.0 50.8 54.0 55.2 55.9 , highest: 117.5 118.8 121.0 121.6 121.7
height
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
22601081172.412.02155.0159.0164.1172.0180.0186.0189.0
lowest : 149.0 149.9 152.0 152.4 152.5 , highest: 192.8 193.0 196.0 197.9 198.0
cgm_use_status
image
nmissingdistinct
22603
 Value                       Current In past, but not current
 Frequency                       107                       79
 Proportion                    0.473                    0.350
                                    
 Value                         Never
 Frequency                        40
 Proportion                    0.177
 

pt_status
nmissingdistinct
22602
 Value      Completed   Dropped
 Frequency        217         9
 Proportion      0.96      0.04
 

trt_group
nmissingdistinct
22602
 Value      CGM Only  CGM+BGM
 Frequency       149       77
 Proportion    0.659    0.341
 

age_as_of_enroll_dt
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
2260530.9994415.8425273143556367
lowest : 19 20 22 24 25 , highest: 71 72 74 75 78
ds_visit

5 Variables   1331 Observations

pt_id
nmissingdistinct
13310226
lowest : 2 3 5 7 8 , highest: 289 290 291 292 293
visit
image
nmissingdistinct
133106
 Value      Randomization  Week 3 Visit  Week 6 Visit Week 13 Visit Week 19 Visit
 Frequency            226           224           224           221           219
 Proportion         0.170         0.168         0.168         0.166         0.165
                         
 Value      Week 26 Visit
 Frequency            217
 Proportion         0.163
 

visitnum
image
nmissingdistinct
133106
 Value          0     1     2     3     4     5
 Frequency    226   224   224   221   219   217
 Proportion 0.170 0.168 0.168 0.166 0.165 0.163
 

visit_dt_days_from_enroll
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
13283256113479.65 30.0 49.0 76.0119.0195.0243.0254.6
lowest : 12 13 14 15 16 , highest: 294 297 315 322 329
visit_dt_days_from_enroll_lag7
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
13283256112779.65 23.0 42.0 69.0112.0188.0236.0247.6
lowest : 5 6 7 8 9 , highest: 287 290 308 315 322
ds_cgm

8 Variables   2785354 Observations

pt_id
nmissingdistinct
27853540226
lowest : 2 3 5 7 8 , highest: 289 290 291 292 293
visit
image
nmissingdistinct
278535406
 Value      Randomization  Week 3 Visit  Week 6 Visit Week 13 Visit Week 19 Visit
 Frequency         489014        479416        472970        462985        454468
 Proportion         0.176         0.172         0.170         0.166         0.163
                         
 Value      Week 26 Visit
 Frequency         426501
 Proportion         0.153
 

visitnum
image
nmissingdistinct
278535406
 Value           0      1      2      3      4      5
 Frequency  489014 479416 472970 462985 454468 426501
 Proportion  0.176  0.172  0.170  0.166  0.163  0.153
 

visit_dt_days_from_enroll_lag7
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
27853540255112578.91 22 42 68111185231247
lowest : 5 6 7 8 9 , highest: 287 290 308 315 322
visit_dt_days_from_enroll
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
27853540255113278.91 29 49 75118192238254
lowest : 12 13 14 15 16 , highest: 294 297 315 322 329
device_dt_tm_days_from_enroll
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
278535403131128.478.89 26 44 71114188234251
lowest : 5 6 7 8 9 , highest: 325 326 327 328 329
device_tmsecs
nmissingdistinct
2785354086400
lowest : 00:00:00 00:00:01 00:00:02 00:00:03 00:00:04 , highest: 23:59:55 23:59:56 23:59:57 23:59:58 23:59:59
glucose_value
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
278535403631159.170.32 74 86112149196245278
lowest : 39 40 41 42 43 , highest: 397 398 399 400 401

2 Explore data

2.1 Drop-outs by treatment group

Should we exclude these from analysis?

table(ds_subject$pt_status,ds_subject$trt_group)
           
            CGM Only CGM+BGM
  Completed      142      75
  Dropped          7       2

2.2 Prior experience with CGM

Could be used for subgroup analyses

table(ds_subject$cgm_use_status, ds_subject$trt_group)
                          
                           CGM Only CGM+BGM
  Current                        69      38
  In past, but not current       54      25
  Never                          26      14

2.3 Number of visits with some data per subject

ds_cgmu <- ds_cgm %>%  
  group_by(pt_id, visitnum) %>% 
  arrange(pt_id, visitnum) %>% 
  filter(row_number()==1) 
#' Number of subjects
length(unique(ds_cgmu$pt_id))
[1] 226
addmargins(table(ds_cgmu$pt_id, ds_cgmu$visitnum))
     
         0    1    2    3    4    5  Sum
  2      1    1    1    1    1    1    6
  3      1    1    1    1    1    1    6
  5      1    1    1    1    0    1    5
  7      1    1    1    1    1    1    6
  8      1    1    1    1    1    1    6
  9      1    1    1    1    1    1    6
  10     1    1    1    1    1    1    6
  11     1    1    1    1    1    1    6
  14     1    1    1    1    1    1    6
  15     1    1    1    1    1    1    6
  16     1    1    1    1    1    1    6
  17     1    1    1    1    1    1    6
  18     1    1    1    1    1    1    6
  19     1    1    1    1    1    1    6
  20     1    1    1    1    1    1    6
  21     1    1    1    1    1    1    6
  22     1    1    1    1    1    1    6
  23     1    1    1    1    1    1    6
  24     1    1    1    1    1    1    6
  26     1    1    1    1    1    1    6
  27     1    1    1    1    1    1    6
  29     1    1    1    1    1    1    6
  30     1    1    1    1    1    1    6
  31     1    1    1    1    1    1    6
  32     1    1    1    1    1    1    6
  33     1    1    1    1    1    1    6
  35     1    1    1    1    1    1    6
  36     1    1    1    1    1    1    6
  37     1    1    1    1    1    0    5
  38     1    1    1    1    1    1    6
  39     1    1    1    0    0    0    3
  40     1    1    1    1    1    1    6
  41     1    1    1    1    1    1    6
  42     1    1    1    1    1    1    6
  43     1    1    1    1    1    1    6
  45     1    1    1    1    1    1    6
  46     1    1    1    1    1    1    6
  47     1    1    1    1    1    1    6
  48     1    1    1    1    1    1    6
  49     1    1    1    1    1    1    6
  50     1    1    1    1    1    1    6
  52     1    0    0    0    0    0    1
  53     1    1    1    1    1    1    6
  54     1    1    1    1    1    1    6
  55     1    1    1    1    1    1    6
  57     1    1    1    1    1    1    6
  58     1    1    1    1    1    1    6
  60     1    1    1    1    1    1    6
  61     1    1    1    1    1    1    6
  62     1    1    1    1    1    1    6
  64     1    1    1    1    1    1    6
  65     1    1    1    1    1    1    6
  67     1    1    1    1    1    1    6
  68     1    1    1    1    1    1    6
  69     1    1    1    1    1    1    6
  70     1    1    1    1    1    1    6
  71     1    1    1    1    1    1    6
  72     1    1    1    1    1    0    5
  73     1    1    1    1    1    1    6
  74     1    1    1    1    1    1    6
  76     1    1    1    1    1    1    6
  77     1    1    1    1    1    1    6
  78     1    1    1    1    1    1    6
  79     1    1    1    1    1    1    6
  80     1    1    1    1    1    1    6
  81     1    1    1    1    1    1    6
  82     1    1    1    1    1    1    6
  86     1    1    1    1    1    1    6
  87     1    1    1    1    1    1    6
  89     1    1    1    1    1    1    6
  90     1    1    1    1    1    1    6
  91     1    1    1    1    1    0    5
  93     1    0    1    1    1    1    5
  95     1    1    1    1    1    1    6
  96     1    1    1    1    1    1    6
  97     1    1    1    1    1    1    6
  98     1    1    1    1    1    1    6
  101    1    1    1    1    1    1    6
  102    1    1    1    1    1    1    6
  103    1    1    1    1    1    1    6
  105    1    1    1    1    1    1    6
  106    1    1    1    1    1    1    6
  108    1    1    1    1    1    1    6
  109    1    1    1    1    1    1    6
  110    1    1    1    1    1    1    6
  111    1    1    1    1    1    1    6
  112    1    1    1    1    1    1    6
  113    1    1    1    1    1    1    6
  115    1    1    1    1    1    1    6
  116    1    1    1    1    1    1    6
  118    1    1    1    1    1    1    6
  119    1    1    1    1    1    1    6
  121    1    1    1    1    1    1    6
  123    1    1    1    1    1    1    6
  124    1    1    1    1    1    1    6
  127    1    1    1    1    1    1    6
  128    1    1    1    1    1    1    6
  129    1    1    1    1    1    1    6
  130    1    1    1    1    1    1    6
  131    1    1    1    1    1    1    6
  132    1    1    1    1    1    1    6
  134    1    1    1    1    1    1    6
  135    1    1    1    1    1    1    6
  136    1    1    1    1    1    1    6
  137    1    1    1    1    1    1    6
  138    1    1    1    1    1    1    6
  139    1    1    1    1    1    1    6
  140    1    1    1    1    1    1    6
  141    1    1    1    1    1    1    6
  143    1    1    1    1    1    1    6
  145    1    1    1    1    1    1    6
  146    1    1    1    1    1    1    6
  147    1    1    1    1    1    1    6
  148    1    1    1    1    1    1    6
  149    1    1    1    1    1    1    6
  152    1    1    1    1    1    1    6
  155    1    1    1    1    1    1    6
  156    1    1    1    1    1    1    6
  157    1    1    1    1    1    1    6
  158    1    1    1    1    1    1    6
  160    1    1    1    1    1    1    6
  162    1    1    1    1    1    1    6
  163    1    1    1    1    1    1    6
  164    1    1    1    1    1    1    6
  165    1    1    1    1    1    1    6
  166    1    1    1    1    1    1    6
  167    1    1    1    1    1    1    6
  168    1    1    1    1    1    1    6
  169    1    1    1    1    1    1    6
  170    1    1    1    1    1    1    6
  171    1    1    1    1    1    1    6
  172    1    1    1    1    1    1    6
  173    1    1    1    1    1    1    6
  174    1    1    1    1    1    1    6
  175    1    1    1    1    1    1    6
  176    1    1    1    1    1    1    6
  177    1    1    1    1    1    1    6
  179    1    1    1    1    1    1    6
  181    1    1    1    1    1    1    6
  183    1    1    1    1    1    1    6
  184    1    1    1    1    1    1    6
  185    1    1    1    1    1    1    6
  186    1    1    1    1    1    1    6
  187    1    1    1    1    1    1    6
  188    1    1    1    1    1    1    6
  189    1    1    1    1    1    1    6
  190    1    1    1    1    1    1    6
  193    1    1    1    1    1    1    6
  197    1    1    1    1    1    1    6
  198    1    1    1    1    1    1    6
  200    1    1    1    1    1    1    6
  201    1    1    1    1    1    1    6
  203    1    1    1    1    1    1    6
  204    1    1    1    1    1    1    6
  205    1    1    1    1    1    1    6
  206    1    1    1    1    1    1    6
  209    1    1    1    1    1    1    6
  210    1    1    1    1    1    1    6
  211    1    1    1    1    1    1    6
  213    1    1    1    1    1    1    6
  214    1    1    1    1    1    1    6
  215    1    1    1    1    1    1    6
  216    1    1    1    1    1    1    6
  217    1    1    1    1    1    1    6
  218    1    1    1    1    1    1    6
  219    1    1    1    1    1    1    6
  220    1    1    1    1    1    1    6
  221    1    1    1    1    1    1    6
  222    1    1    1    1    1    1    6
  223    1    0    0    0    0    0    1
  224    1    1    1    1    1    1    6
  226    1    1    1    1    1    1    6
  227    1    1    1    1    1    1    6
  228    1    1    1    1    1    1    6
  229    1    1    1    1    1    1    6
  231    1    1    1    1    1    1    6
  232    1    1    1    1    1    1    6
  233    1    1    1    1    1    1    6
  234    1    1    1    1    1    1    6
  235    1    1    1    1    1    1    6
  236    1    1    1    1    1    1    6
  239    1    1    1    1    1    1    6
  240    1    1    1    1    1    1    6
  241    1    1    1    1    1    1    6
  243    1    1    1    1    1    1    6
  244    1    1    1    0    1    1    5
  245    1    1    1    1    1    1    6
  246    1    1    1    1    1    1    6
  247    1    1    1    1    1    1    6
  248    1    1    1    1    1    1    6
  249    1    1    0    0    0    0    2
  250    1    1    1    1    1    1    6
  251    1    1    1    1    1    1    6
  252    1    1    1    1    1    1    6
  253    1    1    1    1    1    1    6
  254    1    1    1    1    1    1    6
  256    1    1    1    1    1    1    6
  257    1    1    1    1    1    1    6
  258    1    1    1    1    1    1    6
  260    1    1    1    1    1    1    6
  263    1    1    1    1    1    1    6
  264    1    1    1    1    0    0    4
  265    1    1    1    1    1    1    6
  266    1    1    1    0    0    0    3
  267    1    1    1    1    1    1    6
  269    1    1    1    1    1    1    6
  271    1    1    1    1    1    1    6
  272    1    1    1    1    1    1    6
  273    1    1    1    1    1    1    6
  274    1    1    1    1    1    1    6
  275    1    1    1    1    1    1    6
  276    1    1    1    1    1    1    6
  277    1    1    1    1    1    1    6
  278    1    1    1    1    1    1    6
  280    1    1    1    1    1    1    6
  281    1    1    1    1    1    1    6
  283    1    1    1    1    1    1    6
  284    1    1    1    1    1    1    6
  285    1    1    1    1    1    1    6
  287    1    1    1    1    1    1    6
  288    1    1    1    1    1    1    6
  289    1    0    0    0    0    0    1
  290    1    1    1    1    1    1    6
  291    1    1    1    1    1    1    6
  292    1    1    1    1    1    1    6
  293    1    1    1    1    1    1    6
  Sum  226  222  222  219  218  216 1323

Only a few have missing visits - leave as is?

Next plot shows subjects with data at what visits.

ggplot(ds_cgmu, aes(x=visitnum, y=pt_id, fill=visitnum)) +
  geom_tile(color = "white", size=0.25) +
  scale_y_discrete(expand=c(0,0)) +
  #coord_fixed() +
  scale_fill_brewer(palette = "Paired") +
  theme_bw() +
  labs (title = "Visits with CGM data by subject",
        y = "Subject ID",
        x = "Visit Number")

2.4 Any unusual data values / no data values?

summary(ds_cgm$glucose_value)  
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   39.0   112.0   149.0   159.1   196.0   401.0 

2.5 Plots for 10 subjects: all visits and prior 7 days to visit

#for (i in unique(dd0_1$pt_id)) {
for (i in unique(ds_cgm$pt_id)[1:10]) {
  p <- ggplot(data = subset(ds_cgm, pt_id == i), aes(x = device_dt_tm_days_from_enroll, 
                                                    y = glucose_value, col=visitnum)) +
           geom_point(size=0.5) +
           geom_hline(yintercept=70, color="black", linetype="dashed") +
           geom_hline(yintercept=180, color="black", linetype="dashed") +
           scale_color_brewer(palette = "Paired") +
           theme_bw() +
           #scale_x_date(labels = date_format("%m-%Y")) +
           ggtitle(as.character(i)) +
           guides(col = guide_legend(override.aes = list(size=10)))
  print(p)
}

2.6 Individual trajectories: 10 subjects, all visitis and prior 7 days to visit

#' Look at individual daily trajectories by visit
for (i in unique(ds_cgm$pt_id)[1:10]) {
  pp <- ggplot(data = subset(ds_cgm, pt_id == i), 
               aes(x = device_tm, y = glucose_value, group=as.factor(device_dt_tm_days_from_enroll),
                   col=as.factor(visitnum))) +
    facet_wrap(pt_id~visitnum) +
    geom_line(size=0.1, show.legend=FALSE) +
    theme_bw()+
    geom_hline(yintercept=70, color="black", linetype="dashed") +
    geom_hline(yintercept=180, color="black", linetype="dashed") +
    scale_color_brewer(palette = "Paired") 
  print(pp)
}

2.7 Demographics Table

#Relabel 
var.labels <- c(gender = "Gender",
                ethnicity = "Ethnicity",
                diag_age = "Age at Diagnosis",
                oth_gluc_lower_med = "Other Glucose Lowering Medication",
                edu_level = "Highest Education Level",
                weight = "Weight",
                height = "Height",
                cgm_use_status = "CGM Use",
                pt_status = "Completed Study",
                trt_group = "Treatment Group",
                age_as_of_enroll_dt = "Age at Enrollment"
)
ds_subject <- Hmisc::upData(ds_subject, labels = var.labels) 
Input object size:   37968 bytes;    13 variables    226 observations
New object size:    39544 bytes;    13 variables    226 observations
compareGroups(trt_group ~ pt_status + gender + ethnicity + diag_age + age_as_of_enroll_dt +
                edu_level + weight + height + cgm_use_status,
              data = ds_subject,
              include.miss = TRUE) %>% 
  createTable(show.p.overall = TRUE,
              #hide = c("No"),
              show.n = TRUE) %>%
  export2md(strip = TRUE, first.strip = TRUE)
Summary descriptives table by groups of `Treatment Group’
CGM Only CGM+BGM p.overall N
N=149 N=77
Completed Study: 0.722 226
Completed 142 (95.3%) 75 (97.4%)
Dropped 7 (4.70%) 2 (2.60%)
Gender: 0.511 226
F 71 (47.7%) 41 (53.2%)
M 78 (52.3%) 36 (46.8%)
Ethnicity: 0.352 226
Hispanic or Latino 4 (2.68%) 5 (6.49%)
Not Hispanic or Latino 144 (96.6%) 72 (93.5%)
Unknown/not reported 1 (0.67%) 0 (0.00%)
Age at Diagnosis 20.8 (13.8) 20.6 (13.0) 0.919 226
Age at Enrollment 43.5 (14.1) 45.0 (13.2) 0.434 226
Highest Education Level: 0.300 226
Associate Degree 6 (4.03%) 3 (3.90%)
Bachelor’s Degree 75 (50.3%) 35 (45.5%)
Doctorate Degree 3 (2.01%) 3 (3.90%)
High school graduate/diploma/GED 6 (4.03%) 2 (2.60%)
Master’s Degree 29 (19.5%) 18 (23.4%)
Professional Degree 6 (4.03%) 5 (6.49%)
Some college but no degree 23 (15.4%) 7 (9.09%)
‘Missing’ 1 (0.67%) 4 (5.19%)
Weight 82.7 (15.6) 78.4 (15.6) 0.053 226
Height 173 (10.6) 172 (10.4) 0.792 226
CGM Use: 0.852 226
Current 69 (46.3%) 38 (49.4%)
In past, but not current 54 (36.2%) 25 (32.5%)
Never 26 (17.4%) 14 (18.2%)